/*
*CompilerFX.fx
*
*Created on Apr 5, 2011, 01:28:37 AM
*/

package mythesis.controller;
import javax.tools.*;
import java.io.*;
import java.util.*;
import java.lang.*;

public class CompilerFX {
};

public function compile(fileNumber:Integer):String
{
    var success = true;
    var fileName:String = "compiletest.cmd";
    var fileDel:String  = "compiletest.cmd";
	fileName = "compileai{fileNumber}.cmd";
	fileDel  = "delclass{fileNumber}.cmd";
	    
	// first, delete the class files
	var pdel:Process = Runtime.getRuntime().exec(fileDel);
    pdel.waitFor();
	
	// generate class file
    var p:Process = Runtime.getRuntime().exec(fileName);
    p.waitFor();
    
    // check if class file was generated
    var file:File = new File("C:/Users/ncinco/Eclipse/workspace/Cluedo/Cluedo/AI/CustomAI1.class");
    var fis:FileInputStream = null;
    var bis:BufferedInputStream = null;
    var dis:DataInputStream = null;
    
    try
    {
		fis = new FileInputStream(file);
	}
	catch (e:FileNotFoundException)
	{
	    return "Failed to compile{fileName}.  Please check your usage of IF, WHILE and END.";
	}

	return "Successfully compiled CustomAI{fileNumber}.java.";
    /*
    var result:Integer = (p.exitValue());
	if (result == 0)
	{
	   //System.out.println("Successful compilation.");
	   return "Code {result}: Successfully compiled CustomAI{fileNumber}.java.";
	}
	else
	{
	   //System.out.println("Something went wrong with compilation, that wasn't supposed to happen.  Please try manual compilation for details.");
	   return "Code {result}: Something went wrong with compilation of {fileName}, that wasn't supposed to happen.  Please try manual compilation for details.";
	}
	*/
}